package tech.aistar.day11.pool;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 本类用来演示:创建一个定长线程池，支持定时及周期性任务执行
 *
 * @author: success
 * @date: 2022/8/2 3:35 下午
 */
public class ScheduledPoolDemo {
    public static void main(String[] args) {
        //仅有三个线程对象
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(3);

        System.out.println("main-begin");
        //1. 设置延时2s之后执行
        //每5秒再去执行一次

        executorService.scheduleAtFixedRate(()->{
            //线程的任务
            System.out.println(Thread.currentThread().getName());

        },2,1, TimeUnit.SECONDS);
    }
}
